/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;

import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IPhotoAlbumDao;
import com.qiyou.dao.impl.PhotoAlbumDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.PhotoAlbum;
import com.qiyou.util.DBUtil;

/**
 * 相册数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class PhotoAlbumDaoProxy implements IPhotoAlbumDao {
    private Connection conn = null;
    private IPhotoAlbumDao dao = null;

    public PhotoAlbumDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new PhotoAlbumDaoImpl(conn);
    }

    @Override
    public boolean doCreate(PhotoAlbum album) throws SQLException {
        if (null != album) {
            try {
                return dao.doCreate(album);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doUpdate(PhotoAlbum album) throws SQLException {
        if (null != album) {
            try {
                return dao.doUpdate(album);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(long albumID) throws SQLException {
        if (albumID > 0) {
            try {
                return dao.doDelete(albumID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public PhotoAlbum getPhotoAlbum(long albumID) throws SQLException {
        if (albumID > 0) {
            try {
                return dao.getPhotoAlbum(albumID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<PhotoAlbum> getPhotoAlbums(String userID) throws SQLException {
        if (null!=userID) {
            try {
                return dao.getPhotoAlbums(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<PhotoAlbum> getPhotoAlbums(Object... params)
            throws SQLException {
        if (null!=params) {
            try {
                return dao.getPhotoAlbums(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
